<?php
/**
 * FilialCliente Active Record
 * @author  <your-name-here>
 */
class FilialCliente extends TRecord
{
    const TABLENAME = 'filial_cliente';
    const PRIMARYKEY= 'id_filial_cliente';
    const IDPOLICY =  'max'; // {max, serial}
    
    
    private $bairro;
    private $cliente;

    /**
     * Constructor method
     */
    public function __construct($id = NULL, $callObjectLoad = TRUE)
    {
        parent::__construct($id, $callObjectLoad);
        parent::addAttribute('id_cliente');
        parent::addAttribute('razao_social');
        parent::addAttribute('tipo_filial');
        parent::addAttribute('tipo_inscricao');
        parent::addAttribute('num_inscricao');
        parent::addAttribute('num_cei');
        parent::addAttribute('num_insc_estadual');
        parent::addAttribute('num_insc_municipal');
        parent::addAttribute('num_insc_obra');
        parent::addAttribute('num_emp_pfisica');
        parent::addAttribute('cep');
        parent::addAttribute('nome_pais');
        parent::addAttribute('uf');
        parent::addAttribute('nome_cidade');
        parent::addAttribute('id_bairro');
        parent::addAttribute('tipo_endereco');
        parent::addAttribute('endereco');
        parent::addAttribute('num_endereco');
        parent::addAttribute('cpl_endereco');
        parent::addAttribute('num_ddd');
        parent::addAttribute('num_ddi');
        parent::addAttribute('telefone');
        parent::addAttribute('email');
    }

    
    /**
     * Method set_bairro
     * Sample of usage: $filial_cliente->bairro = $object;
     * @param $object Instance of Bairro
     */
    public function set_bairro(Bairro $object)
    {
        $this->bairro = $object;
        $this->bairro_id = $object->id;
    }
    
    /**
     * Method get_bairro
     * Sample of usage: $filial_cliente->bairro->attribute;
     * @returns Bairro instance
     */
    public function get_bairro()
    {
        // loads the associated object
        if (empty($this->bairro))
            $this->bairro = new Bairro($this->bairro_id);
    
        // returns the associated object
        return $this->bairro;
    }
    
    public function get_nome_cliente()
    {
        // loads the associated object
        if (empty($this->cliente))
            $this->cliente = new Cliente($this->id_cliente);
    
        // returns the associated object
        return $this->cliente->razao_social;
    }

}
